<script setup>
import { computed, useAttrs } from "vue";
import _ from "lodash";
import areaCode from "@/assets/pca-code";

const props = defineProps({
  modelValue: {
    type: Array,
    default: () => []
  },
  placeholder: {
    type: String,
    default: "请输入内容"
  },
  mode: {
    type: String,
    default: "DESIGN"
  },
  required: {
    type: Boolean,
    default: false
  },
  readonly: {
    type: Boolean,
    default: false
  }
});

const emit = defineEmits(["update:modelValue"]);

const $attrs = useAttrs();

const _value = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emit("update:modelValue", val);
  }
});

if (_.isEmpty(_value.value) && !$attrs.disabled) {
  _value.value = $attrs.defaultValue;
}
</script>

<template>
  <div class="form-item-el">
    <div v-if="mode === 'DESIGN'">
      <el-cascader disabled></el-cascader>
    </div>
    <div v-else>
      <el-cascader
        v-model="_value"
        :props="{
          label: 'name',
          value: 'cityCode'
        }"
        :options="areaCode"
        :disabled="$attrs.disabled"
        :placeholder="placeholder"
      ></el-cascader>
    </div>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-cascader) {
  width: 100%;
}
</style>
